package com.ygxsk.carhome.alertview;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import com.ygxsk.carhome.R;

import java.util.List;

/**
 * Project:RecycleWheelView
 * Author:dyping 滚轮列表的选择器
 * Date:2017/7/11 13:40
 */

public class ItemAdapter extends RecyclerView.Adapter<ItemAdapter.ItemViewHolder> {

    Context mContext;

    List<OperationBean> list;

    /**
     * 传递点击条目的内容
     */
    IteminItemClickListener iteminItemClickListener;

    public ItemAdapter(Context mContext, List<OperationBean> list, IteminItemClickListener _iteminItemClickListener) {
        this.mContext = mContext;
        this.list = list;
        this.iteminItemClickListener = _iteminItemClickListener;
    }

    @Override
    public ItemViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

        return new ItemViewHolder(LayoutInflater.from(mContext).inflate(R.layout.item_operation, parent, false));
    }

    @Override
    public void onBindViewHolder(ItemViewHolder holder, final int position) {

        //2018年04月12日关闭无限循环
        //final OperationBean operationBean = list.get(position % list.size());

        final OperationBean operationBean = list.get(position);

        holder.itemName.setText(operationBean.getName());

        holder.itemName.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {

                //LogUtils.d("itchen---holder.itemName--setOnClickListener");

                if (iteminItemClickListener != null) {

                    iteminItemClickListener.onNameClickListener(operationBean);

                    //ToastUtils.showShort("位置"+position);
                } else {
                    //LogUtils.d("itchen--onDialogItemClickListener==null");
                }
            }
        });

        //holder.itemMoeny.setText(list.get(position % list.size()).getMoney());
        //holder.itemYearPercent.setText(list.get(position % list.size()).getYearPercent());
        //holder.itemYearCompletePercent.setText(list.get(position % list.size()).getYearCompletePercent());

        //itchen点击事件内容
        /*holder.itemName.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(mContext,"测试点击名称", Toast.LENGTH_SHORT).show();
            }
        });*/

    }

    @Override
    public int getItemCount() {
        //return Integer.MAX_VALUE;
        return list == null ? 0 : list.size();
    }

    class ItemViewHolder extends RecyclerView.ViewHolder {

        TextView itemName;
        //TextView itemMoeny;
        //TextView itemYearPercent;
        //TextView itemYearCompletePercent;

        public ItemViewHolder(View itemView) {
            super(itemView);

            itemName = (TextView) itemView.findViewById(R.id.textviewitem);

            //itemMoeny = (TextView) itemView.findViewById(R.id.money);
            //itemYearPercent = (TextView) itemView.findViewById(R.id.year_to_year);
            //itemYearCompletePercent = (TextView) itemView.findViewById(R.id.year_complete);


        }
    }
}
